package thread.waitandnotify;

/**
 * @author liweimin
 * @date 2021/4/30 15:57
 * @since
 */
public class Test5 {
    public static final Object lock = new Object();

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println(Thread.currentThread().getName() + "===========wait begin===========");

                    lock.wait();
                    System.out.println(Thread.currentThread().getName() + "===========wait end===========");

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Thread thread2 = new Thread(() -> {
            synchronized (lock) {
                System.out.println(Thread.currentThread().getName() + "===========notify begin===========");
                lock.notify();
                System.out.println(Thread.currentThread().getName() + "===========notify end===========");
            }
        });

        //先开启thread1,再开启thread2 大多数情况下 thread1先等待 thread2再把thread1唤醒
//        thread1.start();
//        thread2.start();


        thread2.start();
        thread1.start();
    }
}
